#define _CRT_SECURE_NO_WARNINGS 1
#pragma warning(disable:6031)
#include<stdio.h>
int main()
{
    int a, b;
    while (scanf("%d %d", &a, &b) != EOF)
    {
        if (a % 4 == 0 && a % 100 != 0 || a % 400 == 0)
        {
            if (b == 1 || b == 3 || b == 5 || b == 7 || b == 8 || b == 10 || b == 12)
            {
                printf("31\n");
            }
            else if (b == 2)
            {
                printf("29\n");
            }
            else
                printf("30\n");
        }
        else
        {
            if (b == 1 || b == 3 || b == 5 || b == 7 || b == 8 || b == 10 || b == 12)
            {
                printf("31\n");
            } 
            else if (b == 2)
            {
                printf("28\n");
            }
            else
                printf("30\n");
        }
    }
    return 0;
}